<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ 部署与实战指南</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-shadow {
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .card-shadow:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 40px rgba(0, 0, 0, 0.15);
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 1.5rem;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            position: relative;
        }
        
        .code-block::before {
            content: attr(data-language);
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            font-size: 0.75rem;
            color: #888;
            text-transform: uppercase;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #e0e0e0, transparent);
            margin: 3rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 1.5rem;
            border-radius: 12px;
            margin: 2rem 0;
        }
        
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
        }
        
        .nav-item {
            transition: all 0.3s ease;
            cursor: pointer;
        }
        
        .nav-item:hover {
            color: #667eea;
            transform: translateX(5px);
        }
        
        h2 {
            position: relative;
            padding-left: 1rem;
        }
        
        h2::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(to bottom, #667eea, #764ba2);
            border-radius: 2px;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl font-bold mb-4">
                    <i class="fas fa-rocket mr-4"></i>RocketMQ 部署与实战指南
                </h1>
                <p class="text-xl opacity-90 max-w-3xl mx-auto">
                    从零开始掌握 Apache RocketMQ 的部署、配置与 SpringBoot 集成，打造高性能分布式消息系统
                </p>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <div class="grid grid-cols-1 lg:grid-cols-4 gap-8">
            <!-- Sidebar Navigation -->
            <div class="lg:col-span-1">
                <div class="bg-white rounded-xl card-shadow p-6 sticky top-6">
                    <h3 class="text-lg font-bold mb-4 text-gray-800">
                        <i class="fas fa-compass mr-2"></i>快速导航
                    </h3>
                    <ul class="space-y-3">
                        <li class="nav-item">
                            <i class="fas fa-server mr-2 text-gray-500"></i>
                            <a href="#deploy" class="text-gray-700">环境搭建与部署</a>
                        </li>
                        <li class="nav-item">
                            <i class="fas fa-terminal mr-2 text-gray-500"></i>
                            <a href="#commands" class="text-gray-700">基本命令行操作</a>
                        </li>
                        <li class="nav-item">
                            <i class="fas fa-code mr-2 text-gray-500"></i>
                            <a href="#springboot" class="text-gray-700">SpringBoot 整合</a>
                        </li>
                    </ul>
                </div>
            </div>

            <!-- Main Content Area -->
            <div class="lg:col-span-3">
                <!-- Section 1: 环境搭建与部署 -->
                <section id="deploy" class="mb-12">
                    <div class="bg-white rounded-xl card-shadow p-8">
                        <h2 class="text-3xl font-bold mb-6 text-gray-800">
                            环境搭建与部署
                        </h2>
                        
                        <!-- 单机部署 -->
                        <div class="mb-8">
                            <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                                <i class="fas fa-desktop mr-2 text-purple-500"></i>单机部署步骤与配置说明
                            </h3>
                            
                            <p class="text-gray-600 mb-4">
                                <span class="drop-cap">R</span>ocketMQ的单机部署是快速上手和测试的理想方式。以下是详细的部署步骤，让您能够在几分钟内搭建起一个完整的消息队列服务。
                            </p>

                            <div class="bg-gray-50 rounded-lg p-6 mb-6">
                                <h4 class="font-semibold text-lg mb-3">
                                    <i class="fas fa-check-circle mr-2 text-green-500"></i>前置条件
                                </h4>
                                <ul class="space-y-2 text-gray-700">
                                    <li><i class="fas fa-chevron-right mr-2 text-gray-400"></i>JDK 1.8+</li>
                                    <li><i class="fas fa-chevron-right mr-2 text-gray-400"></i>Maven 3.2.x+（如需编译源码）</li>
                                    <li><i class="fas fa-chevron-right mr-2 text-gray-400"></i>4GB+ 可用内存</li>
                                </ul>
                            </div>

                            <h4 class="font-semibold text-lg mb-3">
                                <i class="fas fa-download mr-2 text-blue-500"></i>下载与解压
                            </h4>
                            <div class="code-block mb-6" data-language="bash">
# 下载二进制发布包
wget https://archive.apache.org/dist/rocketmq/4.9.4/rocketmq-all-4.9.4-bin-release.zip

# 解压
unzip rocketmq-all-4.9.4-bin-release.zip
cd rocketmq-4.9.4</div>

                            <h4 class="font-semibold text-lg mb-3">
                                <i class="fas fa-memory mr-2 text-orange-500"></i>修改内存配置
                            </h4>
                            <p class="text-gray-600 mb-3">RocketMQ默认的JVM内存配置较高，对于测试环境可以适当调低：</p>
                            <div class="code-block mb-6" data-language="bash">
# 编辑Name Server启动脚本
vi bin/runserver.sh

# 修改以下参数（约在第26行）
JAVA_OPT="${JAVA_OPT} -server -Xms2g -Xmx2g -Xmn1g"
# 改为
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"

# 编辑Broker启动脚本
vi bin/runbroker.sh

# 修改以下参数（约在第30行）
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
# 改为
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"</div>

                            <h4 class="font-semibold text-lg mb-3">
                                <i class="fas fa-play mr-2 text-green-500"></i>启动服务
                            </h4>
                            <div class="code-block mb-6" data-language="bash">
# 启动Name Server
nohup sh bin/mqnamesrv &

# 验证Name Server是否启动成功
tail -f ~/logs/rocketmqlogs/namesrv.log
# 看到"The Name Server boot success..."表示启动成功

# 启动Broker
nohup sh bin/mqbroker -n localhost:9876 &

# 验证Broker是否启动成功
tail -f ~/logs/rocketmqlogs/broker.log
# 看到"The broker[...] boot success..."表示启动成功</div>
                        </div>

                        <div class="section-divider"></div>

                        <!-- 集群部署 -->
                        <div class="mb-8">
                            <h3 class="text-2xl font-semibold mb-4 text-gray-700">
                                <i class="fas fa-network-wired mr-2 text-purple-500"></i>集群部署架构与实施指南
                            </h3>
                            
                            <p class="text-gray-600 mb-6">
                                在生产环境中，通常需要部署RocketMQ集群以提高可用性和吞吐量。以下是典型的集群部署架构：
                            </p>

                            <!-- 架构图 -->
                            <div class="mermaid mb-8">
graph TB
    subgraph "RocketMQ Cluster"
        subgraph "Name Server Cluster"
            NS1[Name Server 1]
            NS2[Name Server 2]
            NS3[Name Server 3]
        end
        
        subgraph "Broker Cluster"
            subgraph "Broker Group A"
                BA1[Broker-A Master]
                BA2[Broker-A Slave]
            end
            subgraph "Broker Group B"
                BB1[Broker-B Master]
                BB2[Broker-B Slave]
            end
        end
        
        P1[Producer 1]
        P2[Producer 2]
        C1[Consumer 1]
        C2[Consumer 2]
        
        P1 --> NS1
        P2 --> NS2
        C1 --> NS3
        C2 --> NS1
        
        NS1 -.-> BA1
        NS2 -.-> BB1
        BA1 --> BA2
        BB1 --> BB2
    end
    
    style NS1 fill:#f9f,stroke:#333,stroke-width:2px
    style NS2 fill:#f9f,stroke:#333,stroke-width:2px
    style NS3 fill:#f9f,stroke:#333,stroke-width:2px
    style BA1 fill:#9f9,stroke:#333,stroke-width:2px
    style BB1 fill:#9f9,stroke:#333,stroke-width:2px</div>

                            <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
                                <div class="bg-blue-50 rounded-lg p-4">
                                    <h4 class="font-semibold mb-2">
                                        <i class="fas fa-layer-group mr-2 text-blue-600"></i>多Master模式
                                    </h4>
                                    <p class="text-sm text-gray-700">
                                        <strong>优点：</strong>简单，无单点故障，性能最高<br>
                                        <strong>缺点：</strong>单个Master宕机期间，该节点上未被消费的消息不可用
                                    </p>
                                </div>
                                <div class="bg-green-50 rounded-lg p-4">
                                    <h4 class="font-semibold mb-2">
                                        <i class="fas fa-sync-alt mr-2 text-green-600"></i>异步复制模式
                                    </h4>
                                    <p class="text-sm text-gray-700">
                                        <strong>优点：</strong>性能高，消息可靠性较好<br>
                                        <strong>缺点：</strong>Master宕机时可能丢失少量消息
                                    </p>
                                </div>
                                <div class="bg-purple-50 rounded-lg p-4">
                                    <h4 class="font-semibold mb-2">
                                        <i class="fas fa-shield-alt mr-2 text-purple-600"></i>同步双写模式
                                    </h4>
                                    <p class="text-sm text-gray-700">
                                        <strong>优点：</strong>